<template>
	<div>
		<div id="div1">

		</div>
	</div>
</template>

<script>
	import E from 'wangeditor'
	export default{
		data(){
			return {
			
			}
		},
		mounted(){
			if(window.$editor){
				window.$editor = {}
			}
			this.init()
		},
		methods:{
			init(){
				let _this = this
				const editor = new E('#div1')
                window.$editor = editor
				editor.create()
				editor.config.customUploadImg = function (resultFiles, insertImgFn) {
				for(let i in resultFiles){
						var formdata = new FormData();
						formdata.append("file",resultFiles[i]);
						let token = sessionStorage.getItem('token')
						let action
						if(_this.$env=='dev'){
							action = _this.$domain + '/uplodeFile/uplodeImageLocal'
						}else{
							action = _this.$domain + '/uplodeFile/uplodeImageH5'
						}
						_this.axios.post(action,formdata,{
								 headers: {
								   Authorization:token
								 }
							 }).then(res => {
						   let result = res.data.data.img_url
						     insertImgFn(result)
						});
					}
				}
				
				 // window.$editor.txt.html() // 获取编辑器内容
				 // editor.txt.html('<p>用 JS 设置的内容</p>') // 重新设置编辑器内容

			},
		}

	}
</script>

<style>
</style>